import subprocess
import os

# 指定 wav 文件夹路径
wav_folder = "wav"
# 指定 ac3 文件夹路径
ac3_folder = "ac3"

# 遍历 wav 文件夹下的所有文件
for file in os.listdir(wav_folder):
    if file.endswith(".wav"):
        # 构建新的文件名
        new_filename = f"22050_{file[:-4]}.ac3"
        # 构建 ffmpeg 命令
        command = f"ffmpeg -i {os.path.join(wav_folder, file)} -acodec pcm_u8 -ar 22050 -ac 1 {os.path.join(ac3_folder, new_filename)}"
        # 执行 ffmpeg 命令
        subprocess.run(command, shell=True)
        print(f"Converted {file} to {new_filename}")

